// 实现懒加载插件
import { useIntersectionObserver } from "@vueuse/core";

export const lazyPlugin = {
    install(app) {
        app.directive("img-lazy", {
            // el : 元素  binding:指令对象
            mounted(el, binding) {
                const { stop } = useIntersectionObserver(el, ([{ isIntersecting }]) => {
                    if (isIntersecting) {
                        el.src = binding.value;
                        stop()
                    }
                });
            },
        });
    }
}

